﻿using System.Collections.Generic;
using System.Data.Entity;
using Domep.Server.BusinessObjects;


namespace Domep.Server.Services.Kernel.DBCommunication
{
    public class ServerContextInitializer : DropCreateDatabaseAlways<ServerContext>
    {
        protected override void Seed(ServerContext context)
        {
            base.Seed(context);


            List<Functionality> functionalities = new List<Functionality>();
            Functionality f1 = new Functionality("Allumer", "Allumer l'appareil", "Signature1");
            Functionality f2 = new Functionality("Eteindre", "Eteins l'appareil", "Signature2");
            Functionality f3 = new Functionality("Fourer", "Foure", "Signature3");
            Functionality f4 = new Functionality("MicroOnder", "Microonde", "Signature4");

            functionalities.Add(f1);
            functionalities.Add(f2);
            functionalities.Add(f3);

            ApplianceModel am1 = new ApplianceModel("Four", "MarqueDuFour", ApplianceType.Oven, functionalities);
            Appliance a1 = new Appliance(new byte[] { 192, 168, 2, 2 }, "00-11-22-33-44-55", "Four", am1, "ReferenceDuFour", "SerialNumberDuFour", 1, 1);
            context.Appliances.Add(a1);

            functionalities = new List<Functionality>();
            functionalities.Add(f1);
            functionalities.Add(f2);
            functionalities.Add(f4);
            ApplianceModel am2 = new ApplianceModel("Micro-Ondes", "MarqueDuMicroOndes", ApplianceType.MicrowaveOven, functionalities);
            Appliance a2 = new Appliance(new byte[] { 192, 168, 2, 3 }, "11-22-33-44-55-66", "Micro-Ondes", am2, "ReferenceDuMicroOndes", "SerialNumberDuMicroOndes", 2, 2);
            context.Appliances.Add(a2);

            //List<Functionality> functionalities = new List<Functionality>
            //{
            //    new Functionality("Allumer", "Allumer l'appareil", "Signature1"),
            //    new Functionality("Eteindre", "Eteins l'appareil", "Signature2"),
            //    new Functionality("Fourer", "Foure", "Signature3"),
            //    new Functionality("MicroOnder", "Microonde", "Signature4")
            //};
            //foreach (Functionality f in functionalities)
            //    context.Functionalities.Add(f);

            ////List<ApplianceModel> applianceModels = new List<ApplianceModel>
            ////{
            //context.ApplianceModels.Add(new ApplianceModel("Four", "MarqueDuFour", ApplianceType.Oven, functionalities));
            //context.ApplianceModels.Add(new ApplianceModel("Micro-Ondes", "MarqueDuMicroOndes", ApplianceType.MicrowaveOven, functionalities));
            ////};
            ////foreach (ApplianceModel am in applianceModels)
            ////    context.ApplianceModels.Add(am);

            //List<Appliance> appliances = new List<Appliance>
            //{
            //    new Appliance(new byte[]{192,168,2,2},"11-22-33-44-55-66","Micro-Ondes",context.ApplianceModels.Find(2),"ReferenceDuMicroOndes","SerialNumberDuMicroOndes",2,2),
            //    new Appliance(new byte[]{192,168,2,3},"00-11-22-33-44-55","Four",context.ApplianceModels.Find(2),"ReferenceDuFour","SerialNumberDuFour",1,1)
            //};
            //foreach (Appliance a in appliances)
            //    context.Appliances.Add(a);

            context.SaveChanges();
        }
    }
}
